package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper trackRecordMapper;

    @Autowired
    private TbBusinessMapper tbBusinessMapper;


    /**
     * 商机跟进记录
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> list(Long id) {
        return trackRecordMapper.list(id);
    }

    /**
     * 添加商机跟进记录
     * @param businessTrackVo
     * @return
     */
    @Override
    public String add(BusinessTrackVo businessTrackVo) {
        //创建商机对象
        TbBusiness tbBusiness = new TbBusiness();
        //获取商机id
        Long businessId = businessTrackVo.getBusinessId();
        //对象拷贝
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        //添加商机id
        tbBusiness.setId(businessId);

        //创建商机跟进记录对象
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        //获取当前用户
        String username = SecurityUtils.getUsername();
        //对象拷贝
        BeanUtils.copyProperties(businessTrackVo,tbBusinessTrackRecord);
        //将用户姓名添加到商机对象中
        tbBusinessTrackRecord.setCreateBy(username);
        //更新商机信息
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        //添加跟进记录
        trackRecordMapper.add(tbBusinessTrackRecord);

        return "添加成功";
    }
}
